			<meta charset="utf-8">
			<?php
			/*
			这段代码为生成中间5页页码的代码，加载数据库正常执行的结果如下  首页12345下一页尾页 并可实现翻页。但这段代码中存在很多错误，需全部解决才能运行
			12345
			*/

			session_start();

			function getCount($as,$table = 'news'){ //修改后function getCount($as,$table = 'news'){
			$sql = "select count(*) as $as from $table";//得到总行数，as：为当前语句的字段或数据表起一个别名
			$count_query = mysql_query($sql);
			$count_result = mysql_fetch_assoc($count_query);//array(sum =>3)
			return $count_result[$as];    //修改后  return $count_result[$as];
			}



			$link = mysql_connect('localhost','root','root');
			$db = mysql_select_db('p301',$link);
			mysql_query('set names utf8');
			define('BASE_URL','http://localhost/error_page.php'); //修改后define('BASE_URL','http://localhost/error_page.php?');

			$curpage =empty($_GET['p'])?1:$_GET['p'];
			$perpage = 2;
			$numberpage =5;
			$count_result = getCount('sum');
			$totalpage = ceil($count_result/$perpage);
			$pevpage = $curpage-1;//上一页
			$nextpage = $curpage+1;//下一页
			$floorpage = floor($numberpage/2);
			$startpage = $curpage - $floorpage;//当前页-2
			$endpage = $curpage + $floorpage;//当前页+2



			if($totalpage <=$numberpage){
			$startpage = 1;
			$endpage = $totalpage;
			}
			if($startpage <= 0){
			//当起始页小于等于0时，表示超出显示范围
			$startpage = 1;
			$endpage = $numberpage;
			}
			if($endpage > $totalpage){
			$startpage = $totalpage - $numberpage;
			$endpage = $totalpage;
			}

			$page = '';
			$page .= '<a href="'.BASE_URL.'p=1" title="First Page">首页</a>';
			if($curpage >= 1){
			$page .= '<a href="'.BASE_URL.'p='.$pevpage.'" title="Previous Page">上一页</a>';
			}
			for($i = $startpage;$i<$endpage;$i++){
			if($i == $curpage){
			//当前页
			$page .='<a href="'.BASE_URL.'p='.$i.'" class="number current" title="'.$i.'">'.$i.'</a>';
			}
			else{
			$page .='<a href="'.BASE_URL.'p='.$i.'" class="number" title="'.$i.'">'.$i.'</a>';
			}
			}
			if($curpage <= $totalpage){
			$page .= '<a href="'.BASE_URL.'p='.$nextpage.'" title="Next Page">下一页</a>';
			}
			$page .= '<a href="'.BASE_URL.'p='.$totalpage.'"  title="Last Page">尾页</a>';
			echo $page;



